const TerserPlugin = require('terser-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

const path = require('path');

const vendorPath = path.resolve(__dirname, './vendor');

console.log('-----vendorPath', vendorPath);

module.exports = {
  mode: process.env.NODE_ENV,
  entry: path.resolve('externals.js'),
  output: {
    path: vendorPath,
    filename: 'vendor.js',
    libraryTarget: 'window',
  },
  plugins: [
    new CleanWebpackPlugin({
      // 清除之前的vendor文件
      root: vendorPath,
    }),
  ],
  optimization: {
    minimizer: [
      new TerserPlugin({
        test: /\.js(\?.*)?$/i,
        extractComments: false,
      }),
    ],
  },
};
